<?php

class Admin extends Controller
{
	/*
	 * constructor
	 */
	function __construct ()
	{
		parent::Controller();
		$this->load->helper('admin');
	}
	
	function index ()
	{
		$menu = get_menu();
		$content = get_content();
		
		$this->load->view('admin/header');
		$this->load->view('admin/leftmenu', array('menu' => $menu));
		$this->load->view('admin/main');
		$this->load->view('admin/footer');
	}
	function page ($page = NULL, $id = NULL)
	{		
		$menu = get_menu();
		$content = get_content();
		
		
		$data = '';
		if (isset($content[$page]))
		{
			$p = $content[$page];
			$p['page'] = $page;
			$query = $content[$page]['query'];
			$query = str_replace('@id', $id, $query);
			if ($content[$page]['type'] == 'list')
			{
				$this->load->model('Articles');
				$results = $this->Articles->get_query($query);
				$data = process_list ($content[$page], $results);
			}
			else if ($p['type'] == 'edit')
			{
				$this->load->model('Articles');
				$results = NULL;
				
				$results = $this->Articles->get_query($query);
				$data = process_edit ($p, $results);
			} 
			$title = isset($p['title']) ? $p['title'] : 'Undefined title';
			$data = '
			<div id="content-box">
				<div id="content-box-header">'.$title.'</div>
				<div id="content-box-content">'
					.$data.'
				</div>
			</div>';
		}
		$this->load->view('admin/header', array('update' => array('order' => '1;3;4;5')));
		$this->load->view('admin/leftmenu', array('menu' => $menu, 'active' => $page));
		$this->load->view('admin/main', array('data' => $data));
		$this->load->view('admin/footer');
	}
}
?>